home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / aclock / modcd.bas < prev    next >
BASIC Source File  |  1999-08-26  |  2KB  |  55 lines

  1. Attribute VB_Name = "Module1"
  2. 'This module contains the OpenFile & CloseFile Subroutines.
  3.  
  4. Global Const CC_RGBINIT = &H1& ' This is the Constant for
  5.                                ' the Flags property of the
  6.                                ' COLOR Common Dialog.
  7.  
  8. Global Const CF_BOTH = &H3&    ' This is the Constant for
  9.                                ' the Flags property of the
  10.                                ' FONTS Common Dialog. You
  11.                                ' can also use:
  12.                                ' CF_SCREENFONTS (&H1&)
  13.                                ' or CF_PRINTERFONTS (&H2&)
  14.  
  15.  
  16. Sub CloseFile(Filename As String)
  17. Dim F As Integer
  18. On Error GoTo CloseError                ' If there is an error, display the error message below.
  19.     
  20.     If Dir(Filename) <> "" Then         ' File already exists, so ask if overwriting is desired.
  21.         response = MsgBox("Overwrite existing file?", MB_YESNO + MB_QUESTION + MB_DEFBUTTON2)
  22.         If response = IDNO Then Exit Sub
  23.     End If
  24.     F = FreeFile
  25.     Open Filename For Output As F       ' Otherwise, open the file name for output.
  26.     Print #F, Form1!txt.Caption    ' Print the current text to the opened file.
  27.     Close F                             ' Close the file
  28.     Filename = "KF4ZPB Clock - FREEWARE" ' Reset the caption of the main form
  29.     Exit Sub
  30. CloseError:
  31.     MsgBox "Error occurred trying to close file, please retry.", 48
  32.     Exit Sub
  33. End Sub
  34.  
  35. Sub OpenFile(Filename As String)
  36. Dim F As Integer
  37.     ' Instruction to open a file.
  38.     If "Project Name Here: " + Filename = frmCD.Caption Then
  39.         Exit Sub
  40.     Else
  41.         On Error GoTo ErrHandler
  42.             F = FreeFile
  43.             Open Filename For Input As F
  44.             frmCD!txtCD.Text = Input$(LOF(F), F)
  45.             Close F
  46.             frmCD.Caption = "Project Name Here: " + Filename
  47.             Exit Sub
  48.     End If
  49. ErrHandler:
  50.     MsgBox "Error occurred while trying to open file, please retry.", 48, "Project Name Here"
  51.     Close F
  52.     Exit Sub
  53. End Sub
  54.  
  55.